<template>
    <div ref="chartRef" class="radar-chart"></div>
</template>

<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import echarts from '@/utils/echart';

const chartRef = ref(null);
let chartObj = null;
const resize = () => {
    chartObj.resize();
};
const init = () => {
    chartObj = echarts.init(chartRef.value);
    const option = {
        tooltip: {
            trigger: 'axis'
        },
        radar: {
            // shape: 'circle',
            indicator: [
                { name: 'Sales', max: 6500 },
                { name: 'Administration', max: 16000 },
                { name: 'Information Technology', max: 30000 },
                { name: 'Customer Support', max: 38000 },
                { name: 'Development', max: 52000 },
                { name: 'Marketing', max: 25000 }
            ]
        },
        series: [
            {
                name: 'Budget vs spending',
                type: 'radar',
                data: [
                    {
                        value: [4200, 3000, 20000, 35000, 50000, 18000],
                        name: 'Allocated Budget'
                    },
                    {
                        value: [5000, 14000, 28000, 26000, 42000, 21000],
                        name: 'Actual Spending'
                    }
                ]
            }
        ]
    };
    chartObj.setOption(option);
    window.addEventListener('resize', resize);
};
onMounted(() => {
    init();
});
onBeforeUnmount(() => {
    window.addEventListener('resize', resize);
});
</script>
<style lang="less" scoped>
.radar-chart {
    width: 100%;
    height: 100%;
}
</style>
